#pragma once
#include <map>
#include <string>
#include <memory>
#include "msg.h"
#include "msg_storer.h"
namespace acl
{
namespace mqtt
{
class client_session;
class subscribe_manager
{
public:
	static subscribe_manager &get_instance ();
	void pub_msg (publish_msg &&msg);

	bool sub (std::shared_ptr<client_session> cli_sess,
			  subscribe_msg::topic_filter topic_filter);
	
	bool unsub (const std::string &topic, const std::string &session_id);

private:
	subscribe_manager ();
private:
	//<topic_name,<client_id, <topic_filter,client_session>>>
	struct sub_info
	{
		subscribe_msg::topic_filter topic;
		std::weak_ptr<client_session > client_session_;
		sub_info &operator=(const sub_info &info)
		{
			topic = info.topic;
			client_session_ = info.client_session_;
			return *this;
		}
	};
	typedef std::map <std::string, sub_info> session_filter_map_t;
	std::map<std::string, session_filter_map_t> topic_map_;
};
}
}